﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyThuVien.Business;

namespace QuanLyThuVien.DataAccess
{
    class DocGiaDAL
    {
        clsDatabase db = new clsDatabase();
        public void ThemMoiDG(DocGia dg)
        {
            db.ThuThiSQL("insert into tbDG values (N'" + dg.MaDG + "',N'" +
                dg.TenDG + "',N'" +
                dg.ChucVu + "',N'" +
                dg.Lop + "',N'" +
                dg.Khoa + "',N'" +
                dg.NgaySinh + "',N'" +
                dg.GioiTinh+ "',N'" +
                dg.GhiChu+ "')");
        }

        public void SuaDG(DocGia dg)
        {
            db.ThuThiSQL("update tbDG set TenDG=N'" + dg.TenDG
                + "',ChucVu=N'" + dg.ChucVu
                + "',Lop=N'"+dg.Lop
                +"',Khoa=N'"+dg.Khoa
                +"',NgaySinh=N'"+dg.NgaySinh
                +"',GioiTinh=N'"+dg.GioiTinh
                +"',GhiChu=N'"+dg.GhiChu+"' where MaDG=N'"+dg.MaDG+"'");
        }

        public void XoaDG(string MaDG)
        {
            db.ThuThiSQL("delete from tbDG where MaDG=N'" + MaDG + "'");
        }

        public void LoadLenDG(DataGridView DG)
        {
            db.LoadLenDG(DG, "select * from tbDG");
        }

        public bool KiemTraMaDG(string MaDG)
        {
          return  db.KiemTra("select count(*) from tbDG where MaDG=N'" + MaDG + "'");
        }

        public void LayMaDGLenCB(ComboBox cb)
        {
           db.LoadLenCombobox(cb, "select MaDG from tbDG", 0);
        }

        public string LayTenDGLenLable(string MaDG)
        {
          return  db.LoadLenLable("select TenDG from tbDG where MaDG=N'" + MaDG + "'");
        }

        public string LayChucVuLenCB(string MaDG)
        {
            return db.LoadLenLable("select ChucVu from tbDG where MaDG=N'" + MaDG + "'");
        }

        public string LoadTenDGLenLable(string MaThe)
        {
            return db.LoadLenLable("select TenDG from tbDG,tbThe where MaThe=N'" + MaThe + "'and tbDG.MaDG=tbThe.MaDG");
        }

        public void LayTenDG(ComboBox cb)
        {
            db.LoadLenCombobox(cb, "select TenDG from tbDG", 0);
        }

        public void LoadLenDG(DataGridView dg,string MaDG)
        {
            db.LoadLenDG(dg, "select * from tbDG where MaDG=N'" + MaDG + "'");
        }

        public void LoadLenDGTheoTenDG(DataGridView dg, string TenDG)
        {
            db.LoadLenDG(dg, "select * from tbDG where TenDG=N'" + TenDG + "'");
        }

        public void LoadLenDGTheoMaThe(DataGridView dg, string MaThe)
        {
            db.LoadLenDG(dg, "select DG.* from tbDG DG ,tbThe T where DG.MaDG=T.MaDG and T.MaThe=N'" + MaThe + "'");
        }

        public void TimKiemTenDGNhanh(DataGridView dg,string DL)
        {
            db.LoadLenDG(dg, "select * from tbDG where TenDG like N'%" + DL + "%'");
        }

        public string LaySoMaDG()
        {
          return  db.LoadLenLable("select count (*) from tbDG");
        }
    }
}
